package pl.com.sthaether.mc.engine.data;

import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;

public class MCValuesRange {

    private DoubleProperty from;
    private DoubleProperty to;

    public MCValuesRange(double from, double to) {
        this.from = new SimpleDoubleProperty(from);
        this.to = new SimpleDoubleProperty(to);
    }

    public boolean contains(double value) {
        return (from.getValue() <= value && to.getValue() > value) || (from.getValue() == value && to.getValue() == value);
    }

    public double getFrom() {
        return from.get();
    }

    public DoubleProperty fromProperty() {
        return from;
    }

    public double getTo() {
        return to.get();
    }

    public DoubleProperty toProperty() {
        return to;
    }

    @Override
    public boolean equals(Object obj) { //#WARNING - this is not normal equals! it is used to get values from map by value instead of range
        return (obj instanceof MCValuesRange && ((MCValuesRange) obj).from.getValue().equals(from.getValue()) && ((MCValuesRange) obj).to.getValue().equals(to.getValue())) || (obj instanceof Double && contains((Double) obj));
    }
}
